/**
 * 充值页面
 * author wim
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_aygsh/base/Constant.dart';

class RechargePage extends StatefulWidget {
  RechargePage({Key key}) : super(key: key);

  @override
  _RechargePageState createState() => _RechargePageState();
}

class _RechargePageState extends State<RechargePage> {
  List<String> services = new List();
  List<bool> bools = new List();
  String pay_way = "alipay";
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    services
      ..add("100")
      ..add("200")
      ..add("500")
      ..add("1000")
      ..add("2000")
      ..add("5000");
    bools
      ..add(false)
      ..add(false)
      ..add(false)
      ..add(false)
      ..add(false)
      ..add(false);
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(
        title: Text(
          '在线充值',
          style: TextStyle(
              color: black,
              fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE)),
        ),
        backgroundColor: white,
        brightness: Brightness.light,
        elevation: 0.2,
        iconTheme: IconThemeData(color: black_99),
      ),
      body: Container(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              decoration: BoxDecoration(
                  color: white, borderRadius: BorderRadius.circular(15)),
              padding:
                  EdgeInsets.all(ScreenUtil.getInstance().setHeight(DP_10)),
              margin: EdgeInsets.fromLTRB(
                  ScreenUtil.getInstance().setHeight(DP_20),
                  ScreenUtil.getInstance().setHeight(DP_20),
                  ScreenUtil.getInstance().setHeight(DP_20),
                  0),
              child: Wrap(
                spacing: ScreenUtil.getInstance().setHeight(0), //主轴上子控件的间距
                runSpacing:
                    ScreenUtil.getInstance().setHeight(0), //交叉轴上子控件之间的间距
                children: creatScope(services), //要显示的子控件集合
              ),
            ),
            Container(
              width: double.infinity,
              height: 1,
              margin: EdgeInsets.fromLTRB(
                  ScreenUtil.getInstance().setHeight(DP_40),
                  0,
                  ScreenUtil.getInstance().setHeight(DP_40),
                  0),
              child: Divider(
                height: 1.0,
                indent: 0.0,
                color: grey,
              ),
            ),
            Container(
              width: double.infinity,
              decoration: BoxDecoration(
                  color: white, borderRadius: BorderRadius.circular(15)),
              padding:
                  EdgeInsets.all(ScreenUtil.getInstance().setHeight(DP_20)),
              margin: EdgeInsets.fromLTRB(
                  ScreenUtil.getInstance().setHeight(DP_20),
                  0,
                  ScreenUtil.getInstance().setHeight(DP_20),
                  ScreenUtil.getInstance().setHeight(DP_20)),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text('输入自定义充值金额',
                      style: TextStyle(
                          color: black,
                          fontSize:
                              ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE))),
                  Row(
                    children: <Widget>[
                      Text(MONEY,
                          style: TextStyle(
                              color: black,
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(BIG_FONT_SIZE * 2 - 15))),
                      Expanded(
                        child: TextField(
                          style: TextStyle(
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(BIG_FONT_SIZE * 2 - 15),
                              color: black),
                          keyboardType: TextInputType.numberWithOptions(),
                          maxLines: 1,
                          minLines: 1,
                          cursorColor: mainColor,
                          onChanged: (value) {
                            // old_code = value;
                          },
                          keyboardAppearance: Brightness.light,
                          decoration: new InputDecoration(
                            contentPadding: EdgeInsets.all(5),
                            hintText: "0.00",
                            border: InputBorder.none,
                            hintStyle: TextStyle(
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(BIG_FONT_SIZE * 2),
                                color: black_99),
                          ),
                        ),
                      ),
                    ],
                  ),
                   Divider(
                    height: 1.0,
                    indent: 0.0,
                    color: grey,
                  ),
                ],
              ),
            ),
            Padding(
              padding:
                  EdgeInsets.all(ScreenUtil.getInstance().setHeight(DP_30)),
              child: Text('选择充值方式',
                  style: TextStyle(
                      color: black,
                      fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE))),
            ),
            Container(
              width: double.infinity,
              padding:
                  EdgeInsets.all(ScreenUtil.getInstance().setHeight(DP_20)),
              margin: EdgeInsets.fromLTRB(
                  ScreenUtil.getInstance().setHeight(DP_20),
                  0,
                  ScreenUtil.getInstance().setHeight(DP_20),
                  ScreenUtil.getInstance().setHeight(DP_20)),
              decoration: BoxDecoration(
                  color: white, borderRadius: BorderRadius.circular(15)),
              child: Column(
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Image.asset(
                        "images/icon_ipay.png",
                        scale: 1.1,
                      ),
                      Container(
                        width: 10,
                      ),
                      Expanded(
                        child: Text('支付宝支付',
                            style: TextStyle(
                                color: black,
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(NORMAL_FONT_SIZE))),
                      ),
                      Checkbox(
                          value: pay_way == "alipay",
                          activeColor: mainColor,
                          checkColor: black_99,
                          materialTapTargetSize: MaterialTapTargetSize.padded,
                          onChanged: (bool x) {
                            if (pay_way == "wechat") {
                              pay_way = "alipay";
                            }
                            setState(() {});
                          }),
                    ],
                  ),
                  Container(
                    height: 5,
                  ),
                  Divider(
                    height: 1.0,
                    indent: 0.0,
                    color: grey,
                  ),
                  Container(
                    height: 5,
                  ),
                  Row(
                    children: <Widget>[
                      Image.asset(
                        "images/icon_wechat.png",
                        scale: 1.1,
                      ),
                      Container(
                        width: 10,
                      ),
                      Expanded(
                        child: Text('微信支付',
                            style: TextStyle(
                                color: black,
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(NORMAL_FONT_SIZE))),
                      ),
                      Checkbox(
                          value: pay_way == "wechat",
                          activeColor: mainColor,
                          checkColor: black_99,
                          materialTapTargetSize: MaterialTapTargetSize.padded,
                          onChanged: (bool x) {
                            if (pay_way == "alipay") {
                              pay_way = "wechat";
                            }
                            setState(() {});
                          }),
                    ],
                  ),
                ],
              ),
            ),
            new Container(
              width: double.infinity,
              margin: EdgeInsets.all(ScreenUtil.getInstance().setHeight(DP_40)),
              height: ScreenUtil.getInstance().setWidth(DP_90),
              decoration: new BoxDecoration(
                  color: Color.fromARGB(255, 254, 140, 16),
                  borderRadius: BorderRadius.circular(DP_80)),
              padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
              child: new FlatButton(
                child: new Padding(
                  padding: EdgeInsets.all(0.0),
                  child: new Text(
                    "确定充值",
                    style: new TextStyle(
                        color: Colors.white,
                        fontSize:
                            ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE)),
                  ),
                ),
                onPressed: () {
                  // _checkSub(context);
                },
              ),
            )
          ],
        ),
      ),
    );
  }

  creatScope(List<String> scops) {
    var result = new List<Widget>();
    for (int i = 0; i < scops.length; i++) {
      result.add(new GestureDetector(
        onTap: () {
          for (int n = 0; n < bools.length; n++) {
            if (i != n) {
              bools[n] = false;
            } else {
              bools[i] = !bools[i];
            }
          }
          if (bools[i]) {
            // car_type+=scops[i].id+",";
          } else {
            // car_type.replaceAll(scops[i].id+",", "");
          }
          setState(() {});
        },
        child: new Container(
          width: (MediaQuery.of(context).size.width -
                  2 * ScreenUtil.getInstance().setHeight(DP_30)) /
              3,
          padding: EdgeInsets.all(ScreenUtil.getInstance().setHeight(DP_10)),
          child: new Container(
            alignment: Alignment.center,
            padding: EdgeInsets.all(ScreenUtil.getInstance().setHeight(DP_10)),
            decoration: BoxDecoration(
                color: Color.fromARGB(255, 253, 246, 245),
                borderRadius: BorderRadius.circular(5),
                border: Border.all(
                    color: bools[i]
                        ? Colors.red[600]
                        : Color.fromARGB(255, 253, 246, 245),
                    width: 2)),
            child: Column(
              children: <Widget>[
                Text(
                  MONEY + scops[i],
                  style: TextStyle(
                      fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
                      color: Color.fromARGB(255, 233, 63, 51)),
                ),
                Text(
                  "送" + scops[i] + "积分",
                  style: TextStyle(
                      fontSize: ScreenUtil.getInstance().setSp(MINI_FONT_SIZE),
                      color: Colors.red[400]),
                )
              ],
            ),
          ),
        ),
      ));
    }
    return result;
  }
}
